package shop

import (
	"context"
	"fast-boot/app/model"
	"github.com/hwUltra/fb-tools/gormx"
	"github.com/jinzhu/copier"

	"fast-boot/app/api/admin/internal/svc"
	"fast-boot/app/api/admin/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
	return &AddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddLogic) Add(req *types.ShopForm) (resp *types.ShopFormResp, err error) {
	item := model.PmsShopModel{}
	if err := copier.Copy(&item, req); err != nil {
		return nil, err
	}

	ct := (*model.PmsShopCache)(gormx.NewCacheTool(l.svcCtx.Config.Cache, l.svcCtx.GormClient.GormDb))
	if err := ct.Create(&item); err != nil {
		return nil, err
	}
	return &types.ShopFormResp{
		Id: item.Id,
	}, nil
}
